package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsIssueMapper;
import com.qf.pojo.DtsIssue;
import com.qf.service.IssueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @version 1.0
 * @auther Administrator
 * @date 2023/2/24 22:06
 */
@Service
public class IssueServiceImpl implements IssueService {

    @Autowired
    private DtsIssueMapper dtsIssueMapper;

    @Override
    public IPage<DtsIssue> findListByQuery(String question, String sort, String order, Integer page, Integer limit) {
        return dtsIssueMapper.selectPage(new Page<DtsIssue>(page,limit),
                new QueryWrapper<DtsIssue>()
                        .like(!StringUtils.isEmpty(question),"question",question)
                        .orderBy(!StringUtils.isEmpty(sort),"ASC".equalsIgnoreCase(order),sort));
    }

    /**
     * 通用问题添加
     * @param dtsIssue
     * @return
     */
    @Override
    public DtsIssue create(DtsIssue dtsIssue) {
        dtsIssueMapper.insert(dtsIssue);
        return dtsIssue;
    }

    /**
     * 通用问题编辑
     * @param dtsIssue
     * @return
     */
    @Override
    public DtsIssue update(DtsIssue dtsIssue) {
        dtsIssueMapper.updateById(dtsIssue);
        return dtsIssue;
    }

    /**
     * 通用问题删除
     * @param dtsIssue
     * @return
     */
    @Override
    public DtsIssue delete(DtsIssue dtsIssue) {
        dtsIssueMapper.deleteById(dtsIssue);
        return dtsIssue;
    }
}
